<?php

namespace Boer\Controller;

use Common\Controller\AdminbaseController;

class ContactController extends AdminbaseController {

    protected $m_Contact;

    function _initialize() {
        parent::_initialize();
        $this->m_Contact= D("Boer/Contact");
    }

    /**
     * 列表页
     */
//    public function index(){
//        $where = array("language"=>session("language"));
//        $count=$this->m_Contact->where($where)->count();
//        $page = $this->page($count, 15);
//        $list = $this->m_Contact
//            ->where($where)
//            ->order("create_time desc")
//            ->limit($page->firstRow , $page->listRows)
//            ->select();
//        $this->assign("page", $page->show('Admin'));
//        $this->assign("list",$list);
//        $this->display();
//    }


    /**
     * 新增
     */
    public function add(){
        $item=$this->m_Contact->where(array('language'=>session("language")))->find();
        $this->assign("item",$item);
        $this->display();
    }

    /**
     * 新增数据提交
     */
    public function add_post(){
        if (IS_POST) {
            $id = I("post.id");
            $insert = I("post.");
            if(empty($id)){
                $insert['create_time'] = time();
                $insert['language'] = session("language");
                $result =$this->m_Contact->add($insert);
            }else{
                $insert['update_time'] = time();
                $result = $this->m_Contact->where(array("id"=>$id))->save($insert);
            }
            if ($result) {
                $this->success("操作成功！");
            } else {
                $this->error("操作失败！");
            }

        }
    }



    // 删除
//    public function delete(){
//        if(isset($_GET['id'])){
//            $id = I("get.id",0,'intval');
//            if ($this->m_Contact->where(array('id'=>$id))->delete() !==false) {
//                $this->success("删除成功！");
//            } else {
//                $this->error("删除失败！");
//            }
//        }else{
//            $this->error("参数有误！");
//        }
//
//    }

}